<html>
<head>
<#import "/common/common.ftl" as netCommon>
<@netCommon.commonStyle />
<title></title>
<@netCommon.commonScript /> 
<@netCommon.commonLayui /> 
</head>
<body class="layui-layout-body show-scroll-y">
	<div class="layuimini-container">
		<form class="layui-form" lay-filter="editFrom" id="editFrom" action="">
			<input type="hidden" name="objectid" id="objectid" value="${objectid!}" />
			<div class="layui-form-item">
				<label class="layui-form-label">位置说明</label>
				<div class="layui-input-block">
					<input type="text" name="wzmc" lay-verify="wzmc"
						placeholder="请输入"  class="layui-input" value="" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">位置编号</label>
				<div class="layui-input-block">
					<input type="text" name="wzbh" lay-verify="wzbh"
						placeholder="请输入"  class="layui-input" value="" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">详细描述</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入内容" name="wzms" lay-verify="wzms" class="layui-textarea"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">位置示意图</label>
				<div class="layui-input-block">
					<button type="button" id="upImg" class="layui-btn"  lay-filter=""><i class="layui-icon">&#xe64a;</i> 上传照片</button>
				</div>
				<div class="layui-input-block" id="wzzp">
					
				</div>
			</div>
			<div class="layui-form-item line-center">
				<button type="submit" class="layui-btn" lay-submit lay-filter="saveBtn">保存</button>
				<button type="reset" class="layui-btn layui-btn-primary"  lay-filter="">重置</button>
			</div>
		</form>
	</div>
	<script type="text/javascript">
	layui.use(["form","layer","upload"], function(){
		var layform = layui.form;
		layform.verify({
			"wzmc":function(value){
				if(stringUtils.isBlank(value)){
					return "请输入位置名称！";
				}
			},
			"wzms":function(value){
				if(stringUtils.isBlank(value)){
					return "请输入位置描述！";
				}
			},
			"wzbh":function(value){
				if(stringUtils.isBlank(value)){
					return "请输入位置编号！";
				}else{
					var oid = $("#objectid").val();
					if(!oid){
						var errMsg = "位置编号已存在！";
						$.ajax({
							url: basePath+"/wzxx/valWzbh",
							type: "post",
							async: false,
							dataType: "json",
							data: {"wzbh":value},    
							success: function(res){
								if(res.code != "0"){
									errMsg = res.msg;
								}else{
									errMsg = "";
								}
							}
						});
						return errMsg;
					}
				}
			}
		});
		$(function(){
			var objId = $("#objectid").val();
			if(objId){
				//获取实体属性对象数据
				$.ajax({
					url: basePath+"/wzxx/detailByOid?objectid="+objId,
					type: "post",
					dataType: "json",
					success: function(data){
						if(data.data.wzbh){
							$("input[name='wzbh']").attr("readonly","readonly");
						}
						layform.val('editFrom', {
							"objectid" : data.data.objectid,
							"wzmc" : data.data.wzmc,
							"wzms" : data.data.wzms,
							"wzbh":data.data.wzbh
						});
						loadWzzpData(data.data.wzzp);
					}
				});
			}
		});
		var upload = layui.upload;
		upload.render({
			elem: '#upImg'
			,accept: "images"
			,acceptMime:"image/*"
			,url: ""
			,auto: false //选择文件后不自动上传
			,choose: function(obj){
			//将每次选择的文件追加到文件队列
			var files = obj.pushFile();
			//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
			obj.preview(function(index, file, result){
				loadWzzpData(result);
			   });
			}
		});
		function loadWzzpData(result){
			$("#wzzp").empty();
			if(result){
				var wzzpImg = $("<img class='image-view' id='wzzpData' name='wzzpData'/>");
				wzzpImg.attr("src",result);
				$("#wzzp").append(wzzpImg);
			}
		}
		layform.on("submit(saveBtn)",function(){
			var pData = layform.val('editFrom');
			if($("#wzzpData").length > 0){
				pData.wzzp = $("#wzzpData").attr("src");
			}
			$.ajax({
				url: basePath+"/wzxx/doSave",
				type: "post",
				dataType: "json",
				data: pData,    
				success: function(res){
					showMsg.alert(res.msg,function(){
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.frames[0].loadStsxTable();
					});
				}
			});
			return false;
		});
	});
	</script>
</body>
</html>